/*************************************************
Author: will
Date: 10/11/2012
Description:
Notes:
*************************************************/

#ifndef __CUserEquip_h__
#define __CUserEquip_h__

#include "commclass.h"
#include "CTArray.h"
#include "CTHashObjectMgr.h"

#define INVALID_EQUIP_ID    0xFFFFFFFF

class CSingleEquipAttr{
public:
    CSingleEquipAttr()
    {
        Clear();
    }

    void Clear()
    {
        _stSingleEquipAttr.Clear();
    }

    CTArray<CAttrPair, MAX_ATTR_TYPE_PER_EQUIP>  _stSingleEquipAttr;
};

typedef CTLib::CTHashObjectMgr<unsigned int64, CSingleEquip> T_USER_EQUIP_HASH;
class CUserEquip
{
public:
	CUserEquip()
    {
        _uiGID = 0;
        _uiEquipSeqId = 0;
    }

    virtual ~CUserEquip()
    {

    }

    void Clear()
    {
        _uiGID = 0;
        _uiEquipSeqId = 0;
        for (int iIndex = _stEquipHash.GetHeadIndex();
            iIndex >= 0;
            iIndex = _stEquipHash.GetHeadIndex())
        {
            _stEquipHash.HashFreeByIndex(iIndex);
        }

    }

    static int CountSize()
    {
        return T_USER_EQUIP_HASH::CountSize(MAX_EQUIP_COUNT_PER_USER);
    }

	unsigned int GetEquipId(unsigned int uiConfigId);

    int CreateEquip(unsigned int uiEquipID, unsigned short usEquipConfigID, unsigned short usStrengthLevel, CSingleEquip & stEquip);

    int GetEquipIndex (unsigned int uiEquipId);
    
    int CreateEquip (unsigned short usEquipConfigID, unsigned int & uiEquipId);

    void DelEquip (unsigned int uiEquipId);

    CSingleEquip & GetEquip(int iEquipIndex)
    {
        return _stEquipHash[iEquipIndex];
    }

    int Init(const char* sBuff)
    {
        return _stEquipHash.Init(sBuff, MAX_EQUIP_COUNT_PER_USER);
    }

    int CheckBeforeAdd (unsigned short usEquipConfigID);

public:
    unsigned int        _uiGID;
	unsigned int      _uiEquipSeqId;       //分配装备ID 的序列号
    T_USER_EQUIP_HASH   _stEquipHash;
};


#endif // __CUserEquip_h__

